<template>
  <el-button type="primary" @click="popupEnumAdd = true">
  <el-icon><DocumentAdd /></el-icon>
    枚举
  </el-button>

  <el-table :data="tableData" v-loading="loading" style="width: 100%">
    <el-table-column prop="id" label="枚举ID" width="180" />
    <el-table-column prop="name" label="枚举名" width="180" />
    <el-table-column prop="inner" label="内置" width="180" />
    <el-table-column prop="created_at" label="创建时间" width="180" />
  </el-table>
  <EnumAdd v-model="popupEnumAdd" @success="refresh"></EnumAdd>
  <EnumUpdate v-model="popupEnumUpdate" @success="refresh"></EnumUpdate>
</template>

<script setup>
import {ref, onMounted} from 'vue'
import apiEnum from '@/api/system/enum'
import EnumAdd from '@/components/Popup/System/EnumAdd.vue'
import EnumUpdate from '@/components/Popup/System/EnumUpdate.vue'

const popupEnumAdd = ref(false)
const popupEnumUpdate = ref(false)

const tableData = ref(null)
const searchQuery = ref('')
const loading = ref(true)

// 获取表格数据
const fetchTableData = async () => {
  try {
    const params = { q: searchQuery.value }
    const response = await apiEnum.getEnums(params)
    tableData.value = response.data || []
  } catch (error) {
    console.error('获取数据失败:', error)
  }
  finally {
    loading.value = false
  }
}

// 初始化获取数据
onMounted(() => {
  fetchTableData()
})

const refresh = () => {
  fetchTableData()
}
</script>
